home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / demostuf / flame1.pas < prev    next >
Pascal/Delphi Source File  |  1994-07-25  |  5KB  |  299 lines

  1. program FLAMES;
  2. {
  3.   Flame #1
  4.   - by Bjarke Viksφe
  5.   may 1994
  6.  
  7.   THIS PROGRAM WAS CODED BY BJARKE VIKS0E.
  8.   YOU ARE FREE TO DO WHATEVER YOU WANT WITH THIS PIECE OF CODE.
  9.   E-MAIL ME AT: dat92230@rix02.lyngbyes.dk IN 1994 FOR CHAT AND CODE.
  10.  
  11.   Fairly simple to make. One bug remains.
  12.   Got the idea from PCGPE 1.0. Read that for explanation.
  13. }
  14.  
  15. {$A+,B-,G+,E+,I+,N-,X+}
  16.  
  17. uses
  18.     DEMOINIT;
  19.  
  20. (*{$DEFINE DEBUG}*)
  21.  
  22. const
  23.     MAXX = 160;
  24.     MAXY = 70;
  25.  
  26. type
  27.     pBigArray = ^BigArrayType;
  28.     BigArrayType = array[0..MAXY-1, 0..MAXX-1] of byte;
  29.  
  30. var
  31.     startpos : integer;
  32.     startbuffer : pBigArray;
  33.  
  34. const
  35.     display1 : word = $0000;
  36.     display2 : word = $4000;
  37.     display3 : word = $8000;
  38.  
  39. (*
  40. {$DEFINE FLICKER}
  41. const
  42.     FLICKERCONST = 8;
  43. *)
  44.  
  45. (*------------------------------------------------*)
  46.  
  47. procedure FaseColors(a,b, c1,c2,c3, d1,d2,d3 : integer);
  48. var
  49.     i : integer;
  50.     r1,g1,b1 : longint;
  51.     n,nadd : integer;
  52. begin
  53.     n:=1;
  54.     nadd:=longdiv(256,b-a);
  55.     for i:=a to b do begin
  56.         r1:=(longdiv(longmul(d1-c1,n),256))+c1;
  57.         g1:=(longdiv(longmul(d2-c2,n),256))+c2;
  58.         b1:=(longdiv(longmul(d3-c3,n),256))+c3;
  59.         SetRGB(i, r1,g1,b1);
  60.         inc(n,nadd);
  61.     end;
  62. end;
  63.  
  64. procedure SetColors;
  65. var
  66.     i : integer;
  67. begin
  68.     FaseColors(0,4, 0,0,0, 0,0,0);
  69.     FaseColors(5,9, 0,0,0, 0,0,6);
  70.     FaseColors(10,45, 0,0,6, 43,0,0);
  71.     FaseColors(46,75, 43,0,0, 63,30,10);
  72.     FaseColors(76,85, 63,30,10, 63,60,10);
  73.     FaseColors(86,149, 63,60,10, 63,63,63);
  74.     FaseColors(150,255, 63,63,63, 63,43,0);
  75. end;
  76.  
  77.  
  78. procedure InitDemo;
  79. var
  80.     i : integer;
  81. begin
  82.     Randomize;
  83.     ClearWholeScreen;
  84.     SetColors;
  85.     startpos:=0;
  86.     New(startbuffer);
  87.     FillChar(startbuffer^,sizeof(BigArrayType),0);
  88. end;
  89.  
  90. procedure UninitDemo;
  91. var
  92.     i : integer;
  93. begin
  94.     Dispose(startbuffer);
  95. end;
  96.  
  97.  
  98. (*------------------------------------------------*)
  99.  
  100. procedure SwapDisplay;
  101. var
  102.     temp : word;
  103. begin
  104.     temp:=display3;
  105.     display3:=display2;
  106.     display2:=display1;
  107.     display1:=temp;
  108.     SetAddress(Ptr(SEGA000,display2));
  109. end;
  110.  
  111.  
  112. (*------------------------------------------------*)
  113.  
  114. procedure MakeRandomStuff;
  115. var
  116.     i : integer;
  117.     thisy : word;
  118. begin
  119.     thisy:=startpos+(MAXY-3);
  120.     if (thisy >= MAXY) then dec(thisy,MAXY);
  121.  
  122.     for i:=1 to MAXX-2 do
  123.         if (random(2)=0) then startbuffer^[thisy,i]:=255
  124.         else startbuffer^[thisy,i]:=20;
  125. end;
  126.  
  127.  
  128. procedure SmoothArray; assembler;
  129. asm
  130.     push    ds
  131.     lds    di,startbuffer
  132.     mov    ax,ds
  133.     mov    es,ax
  134.     xor    ax,ax
  135.     xor    bx,bx
  136. {$IFDEF FLICKER}
  137.     mov    dl,FLICKERCONST
  138. {$ENDIF}
  139.     cld
  140.  
  141.     add    di,(MAXX)
  142.     mov    dh,(MAXY-2)
  143. @loop1:
  144.     mov    cx,MAXX
  145. @loop2:
  146.     mov    al,[di]
  147.     add    al,[di+1]
  148.     adc    ah,bl
  149.     add    al,[di-MAXX]
  150.     adc    ah,bl
  151.     add    al,[di+MAXX]
  152.     adc    ah,bl
  153. {$IFDEF FLICKER}
  154.     xor    al,dl
  155. {$ENDIF}
  156.     shr    ax,2
  157.     jz        @no1
  158.     dec    al
  159. @no1:
  160.     stosb
  161.     loop    @loop2
  162.     dec    dh
  163.     jnz    @loop1
  164.  
  165.     mov    ax,SEG @DATA
  166.     mov    ds,ax
  167.     lds    di,startbuffer
  168.     xor    ax,ax
  169.     mov    cx,MAXX
  170. @loop_1line:
  171.     mov    al,[di]
  172.     add    al,[di+1]
  173.     adc    ah,bl
  174.     add    al,[di+(MAXX*(MAXY-1))]
  175.     adc    ah,bl
  176.     add    al,[di+MAXX]
  177.     adc    ah,bl
  178. {$IFDEF FLICKER}
  179.     xor    al,dl
  180. {$ENDIF}
  181.     shr    ax,2
  182.     jz        @no2
  183.     dec    al
  184. @no2:
  185.     stosb
  186.     loop    @loop_1line
  187.  
  188.     mov    ax,SEG @DATA
  189.     mov    ds,ax
  190.     lds    di,startbuffer
  191.     add    di,(MAXX*(MAXY-1))
  192.     xor    ax,ax
  193.     mov    cx,MAXX-1
  194. @loop_last_line:
  195.     mov    al,[di]
  196.     add    al,[di+1]
  197.     adc    ah,bl
  198.     add    al,[di-(MAXX*(MAXY-1))]
  199.     adc    ah,bl
  200.     add    al,[di-MAXX]
  201.     adc    ah,bl
  202. {$IFDEF FLICKER}
  203.     xor    al,dl
  204. {$ENDIF}
  205.     shr    ax,2
  206.     jz        @no3
  207.     dec    al
  208. @no3:
  209.     stosb
  210.     loop    @loop_last_line
  211.  
  212.     pop    ds
  213. end;
  214.  
  215.  
  216. (*------------------------------------------------*)
  217.  
  218. procedure CopyArray2Screen(arrayoffset : integer); assembler;
  219. asm
  220.     push    ds
  221.     mov    es,SEGA000
  222.     mov    di,display1
  223.     add    di,WIDTH*35
  224.     mov    dx,startpos
  225.     lds    si,startbuffer
  226.     add    si,arrayoffset
  227.     mov    ax,MAXY-4
  228.     cld
  229. @copy1:
  230.     mov    cx,(MAXX)/2
  231.     push    ax
  232. @copy2:
  233.     movsb
  234.     inc    si {only copy every 2nd pixel... other pixel is copied later!}
  235.     loop    @copy2
  236.  
  237.     inc    dx
  238.     cmp    dx,MAXY
  239.     jb        @noswap
  240.     xor    dx,dx
  241.     sub    si,(MAXY*MAXX)
  242. @noswap:
  243.     pop    ax
  244.     dec    ax
  245.     jnz    @copy1
  246.     pop    ds
  247. end;
  248.  
  249. procedure CopyScreen;
  250. var
  251.     newoffset : integer;
  252. begin
  253.     newoffset:=longmul(startpos,MAXX);
  254.     SetBitplanes(3);
  255.     CopyArray2Screen(newoffset);
  256.     SetBitplanes(12);
  257.     CopyArray2Screen(newoffset+1);
  258. end;
  259.  
  260.  
  261. (*------------------------------------------------*)
  262.  
  263. procedure RunOnce;
  264. var
  265.     i : integer;
  266. begin
  267.     SwapDisplay;
  268.     while retraces=0 do ;
  269.     retraces:=0;
  270. {$IFDEF DEBUG}
  271.     i:=total_retraces;
  272.     while i=total_retraces do ;
  273.     SetRGB(0,30,0,0);
  274. {$ENDIF}
  275.  
  276.     MakeRandomStuff;
  277.     SmoothArray;
  278.     CopyScreen;
  279.     inc(startpos);    if (startpos = MAXY) then startpos:=0;
  280.  
  281. {$IFDEF DEBUG}
  282.     SetRGB(0,0,0,0);
  283. {$ENDIF}
  284. end;
  285.  
  286.  
  287. begin
  288.     OpenScreen;
  289.     Screen_Off;
  290.     SetLinerepeat(3);
  291.     InitDemo;
  292.     SetAllInterrupts;
  293.     Screen_On;
  294.     repeat RunOnce until Key='e';
  295.     RestoreAllInterrupts;
  296.     UninitDemo;
  297.     CloseScreen;
  298. end.
  299.